// createRouter:     创建router实例对象      地址栏不带#
// createWebHistory: 创建history模式的路由   地址栏带 #
import { createRouter, createWebHistory } from 'vue-router'

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    // 一级路由，首页
    { 
      path: '/',
      component: () => import('@/views/Layout/index.vue'),
      // 二级子路由
      children: [
        // path为空是默认进入
        { path: '', component: () => import('@/views/Home/index.vue') },
        { path: 'category/:id', component: () => import('@/views/Category/index.vue') },
        { path: 'category/sub/:id', component: () => import('@/views/SubCategory/index.vue') },
        { path: 'detail/:id', component: () => import('@/views/Detail/index.vue') },
        { path: 'cartlist', component: () => import('@/views/CartList/index.vue') },
        { path: 'checkout', component: () => import('@/views/Checkout/index.vue') },
        { path: 'pay', component: () => import('@/views/Pay/index.vue') },
        { path: 'paycallback', component: () => import('@/views/Pay/PayBack.vue') },
        {
          path: 'member',
          component: () => import('@/views/Member/index.vue'),
          redirect: 'member/user',
          // 三级子路由
          children: [
            { path: 'user', component: () => import('@/views/Member/components/UserInfo.vue') },
            { path: 'order', component: () => import('@/views/Member/components/UserOrder.vue') }
          ]
        },
      ]
    }, 
    { path: '/login', component: () => import('@/views/Login/index.vue') }, // 一级路由，登录页
  ],
  // 路由滚动行为定制 点击路由跳转会回到页面顶部
  scrollBehavior() {
    return {
      top: 0
    }
  }
})

export default router
